from pyplog.blog.archive import archive
from pyplog.blog.models import Category
from pyplog.config import config
from pyplog.pages.models import Page
from pyplog.util.query import cached_querysets

cached_querysets.add(Category)
cached_querysets.add(Page)

def blog_archive(request):
	"""
	Adds information needed for rendering the blog archive and category list.
	"""
	context = {}
	if request.path.startswith("/blog"): # rather hacky, but still the best solution imo
		context["categories"] = cached_querysets[Category].order_by("slug")
		context["archive"] = archive
	return context

def pages(request):
	"""
	Adds a list of pages to show as additional menu items.
	"""
	return { "pages_list" : cached_querysets[Page].filter(show_in_menu = True) }
	
def pyplog_settings(request):
	"""
	Provides access to site configuration.
	"""
	return { "config" : config }
